package com.ruoyi.product.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.SecdriverProductType;
import com.ruoyi.product.service.ISecdriverProductTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品分类Controller
 * 
 * @author ruoyi
 * @date 2022-05-04
 */
@RestController
@RequestMapping("/product/type")
public class SecdriverProductTypeController extends BaseController
{
    @Autowired
    private ISecdriverProductTypeService secdriverProductTypeService;

    /**
     * 查询产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('product:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(SecdriverProductType secdriverProductType)
    {
        startPage();
        List<SecdriverProductType> list = secdriverProductTypeService.selectSecdriverProductTypeList(secdriverProductType);
        return getDataTable(list);
    }

    /**
     * 查询所有产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('product:type:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(SecdriverProductType secdriverProductType)
    {
        List<SecdriverProductType> list = secdriverProductTypeService.selectSecdriverProductTypeList(secdriverProductType);
        return AjaxResult.success(list);
    }

    /**
     * 导出产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('product:type:export')")
    @Log(title = "产品分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SecdriverProductType secdriverProductType)
    {
        List<SecdriverProductType> list = secdriverProductTypeService.selectSecdriverProductTypeList(secdriverProductType);
        ExcelUtil<SecdriverProductType> util = new ExcelUtil<SecdriverProductType>(SecdriverProductType.class);
        return util.exportExcel(list, "产品分类数据");
    }

    /**
     * 获取产品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:type:query')")
    @GetMapping(value = "/{productTypeId}")
    public AjaxResult getInfo(@PathVariable("productTypeId") Long productTypeId)
    {
        return AjaxResult.success(secdriverProductTypeService.selectSecdriverProductTypeById(productTypeId));
    }

    /**
     * 新增产品分类
     */
    @PreAuthorize("@ss.hasPermi('product:type:add')")
    @Log(title = "产品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SecdriverProductType secdriverProductType)
    {
        return toAjax(secdriverProductTypeService.insertSecdriverProductType(secdriverProductType));
    }

    /**
     * 修改产品分类
     */
    @PreAuthorize("@ss.hasPermi('product:type:edit')")
    @Log(title = "产品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SecdriverProductType secdriverProductType)
    {
        return toAjax(secdriverProductTypeService.updateSecdriverProductType(secdriverProductType));
    }

    /**
     * 删除产品分类
     */
    @PreAuthorize("@ss.hasPermi('product:type:remove')")
    @Log(title = "产品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productTypeIds}")
    public AjaxResult remove(@PathVariable Long[] productTypeIds)
    {
        return toAjax(secdriverProductTypeService.deleteSecdriverProductTypeByIds(productTypeIds));
    }
}
